<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
   <% String path=request.getContextPath(); 
   String basePath=request.getScheme()
    + "://" + request.getServerName() + ":" + request.getServerPort() + path
    + "/"; 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>修改密码</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<style type="text/css">
.input_text{width:180px;background-color:white;}
#modifyPwdDiv1{
margin:100px auto;
}
.mbtn{width:60px;height:30px;background-color: #538ED2;border:0px;color:white;font-size:14px;cursor: hand;}
</style>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
 <script type="text/javascript">
 //修改密码
 function modifyPwd(){
 	if(!checkBeforeModify()) return;
 	var oldPwd = $.trim($('#oldPwd').val());
 	var newp = $.trim($('#newPwd').val());
 	var surep = $.trim($('#sureNewPwd').val());
 	$.openLoading();
 	$.ajax({
 		url : "<%=path%>/systemManager/userManagement/modifyPwd",
 		type : 'POST',
 		async : true,
 		data:{"oldPwd":oldPwd,"newPwd":newp,sureNewPwd:surep},
 		dataType:'json',
 		success:function(data){
 			$.closeLoading();
 			if(data!=null&&data.result=="error"){
 				$.message("error",data.message);
 			}else{
 				$('#oldPwd').val('');
 				$('#newPwd').val('');
 				$('#sureNewPwd').val('');
 				if($.validate(data))return;
 			}
 				init();
 		}
 	});
 }

 //关闭  窗口
 function closeCurrentDIV(obj){
 		$("#"+obj).CloseDiv();	
 }

 //打开修改密码窗口DIV
 function openModifyPwdDiv(){
 	$("#modifyPwdDiv").OpenDiv();
 	$('#oldPwd').val("");
 	$('#newPwd').val("");
 	$('#sureNewPwd').val("");
 	$('#oldpwderror').html("");
 	$('#newpwderror').html("");
 	$('#surepwderror').html("");
 }


 //校验输入的密码
 function checkPwd(obj,errorMsg,inputObj){
 	var newp = $.trim($('#newPwd').val());
 	var surep = $.trim($('#sureNewPwd').val());
 	setUseable();
 }

 //点击保存按钮 之前校验密码
 function checkBeforeModify(){
 	var oldp = $.trim($('#oldPwd').val());
 	var newp = $.trim($('#newPwd').val());
 	var surep = $.trim($('#sureNewPwd').val());
 	if(oldp.length==0){
 		$.message("error","请输入旧密码");
 		return false;
 	}
 	
 	if(oldp.length>0 && newp.length==0){
 		$.message("error","请输入新密码");
 		$('#newPwd').focus();
 		return false;
 	}else if(oldp.length>0 && newp.length < 8){
 		$.message("error","密码长度至少8位字符");
 		$('#newPwd').focus();
 		return false;
 	}
 	
 	if(setUseable()){
 		if(newp.length>=8 && surep.length==0){
 			$.message("error","请输入确认新密码");
 			$('#sureNewPwd').focus();
 			return false;
 		}else if(newp!=surep){
 			$.message("error","两次密码输入不一样");
// 			$('#surePwd').focus();
 			return false;
 		}
 		return true;
 	}
 	return true;
 }

 //新密码和旧密码输入内容符合特定规则才能允许确认密码
 function setUseable(){
 	var oldp = $.trim($('#oldPwd').val());
 	var newp = $.trim($('#newPwd').val());
 	var surep = $.trim($('#sureNewPwd').val());
 	var reg=/^((?=.*[0-9])(?=.*[a-zA-Z])(?=.*[\u0020-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]).{8,})$/;
 	if((oldp.length>0)&&(reg.test(newp))){
 		$('#sureNewPwd').attr('disabled',false);
 		return true;
 	}else{
 		$('#sureNewPwd').attr('disabled','disabled');
 		return false;
 	}
 }


 function use(){
 	var oldp = $.trim($('#oldPwd').val());
 	var newp = $.trim($('#newPwd').val());
 	var reg=/^((?=.*[0-9])(?=.*[a-zA-Z])(?=.*[\u0020-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]).{8,})$/;
 	if((oldp.length>0)&&(reg.test(newp))){
 		$('#sureNewPwd').attr('disabled',false);
 	}else{
 		$('#sureNewPwd').attr('disabled',true);
 	}
 }
 
 function  init(){
	 $('#sureNewPwd').attr('disabled',true);
 }

 function resetPwd(){
	 init();
	 $('#oldpwderror').html('');
	 $('#newpwderror').html('');
	 $('#surepwderror').html('');
	 $('#oldPwd').val('');
	 $('#newPwd').val('');
	 $('#sureNewPwd').val('');
 }
    </script>
</head>

<body onload="init()">
	<div class="current" style="border:0px solid red;">
           <table class="current_table_1">
              <tbody><tr class="f2">
                <td><img src="./images/current_1.jpg"></td>
                  <td class="current_table_1_td">
                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                  <span style=" color:#136bab; ">系统管理
                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>修改密码
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
              <!-- <tr><td style="height:10px;"></td></tr> -->
           </tbody></table>
      </div>
<div style="width:100%;height:93%;border:1px solid #bbcddb;padding:0 auto;margin-top:10px; background-color: #f6f7f9" >
	<form action="">
  		<div id="modifyPwdDiv" style="border:0px solid gray;width:100%;margin:90px auto;" align="center">
		
		<table  id="saveAppTable" style="height:180px;width:520px;font-size:13px;"align="center" >
			<tr><td colspan="3" height="20px">&nbsp;</td></tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%">旧密码：&nbsp;&nbsp;</td>
				<td style="text-align:left;border-right:0px;height:40px;" width="40%"><input type="password" id="oldPwd" class="input_text" onkeyup="use()" onblur="checkPwd(this,'oldpwderror','oldPwd')"><span class="red">*</span></td>
				<td width="30%" style="text-align:left;border:0px solid black; ">
					<div id="oldpwderror" style="text-align:left;"></div> 
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%">新密码：&nbsp;&nbsp;</td>
				<td style="text-align:left;border-right:0px;height:40px;" width="40%"><input type="password" id="newPwd" class="input_text" onkeyup="use()" onblur="checkPwd(this,'newpwderror','newPwd')" ><span class="red">*</span></td>
				<td width="30%" style="text-align:left;vertical-align:middle;">
					<div id="newpwderror" style="width:100%;text-align: left;"></div>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%">&nbsp;</td>
				<td style="text-align:left;border-right:0px;color:gray;" width="40%">（密码长度至少8位字符，包含字母、数字、特殊字符）</td>
				<td width="30%">&nbsp;</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="30%">确认新密码：&nbsp;&nbsp;</td>
				<td style="text-align:left;border-right:0px;height:40px;" width="40%"><input type="password" id="sureNewPwd" class="input_text" onblur="checkPwd(this,'surepwderror','sureNewPwd')"><span class="red">*</span></td>
				<td width="30%" style="text-align:left;">
					<div id="surepwderror" style="width:100%;text-align: left;"></div>
				</td>
			</tr>
			<tr>
				<td width="30%">&nbsp;&nbsp;</td>
				<td style="text-align:left;height:40px;" width="40%">
					<input type="button" id="saveBtn" value="保存" onclick="modifyPwd()" class="input_button_1"/>
					<input type="reset" value="重置" class="input_button_1" onclick="resetPwd()"/>
				</td>
				<td width="30%">&nbsp;</td>
			</tr>
		</table>
	</div>
	</form>
	</div>
</body>
</html>
